package com.seckill.controller;

import com.seckill.annotation.LogRecord;
import com.seckill.entity.Blog;
import com.seckill.entity.SeckillUser;
import com.seckill.enums.ResultEnum;
import com.seckill.result.Result;
import com.seckill.service.BlogService;
import com.seckill.vo.LoginVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Collections;

@Controller
@RequestMapping("/seckill")
public class SeckillController {
    @Autowired
    private BlogService blogService;
    @RequestMapping("/index")
    @ResponseBody
    public Result<Blog> toSeckill(){
        Blog blog = blogService.getBlog(1);
        return Result.success(blog);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Result<Integer> update(){
        return Result.success(blogService.updateBlog(1));
    }

    @RequestMapping("/thymeleaf")
    public String toThymeleaf(Model model){
        model.addAttribute("name","yanshang");
        return "hello";
    }

    @RequestMapping("/error")
    @ResponseBody
    @LogRecord("error记录时间")
    public Result<String> error(SeckillUser seckillUser){
        System.out.println(seckillUser);
        return Result.error(ResultEnum.SERVER_ERROR);
    }

    @RequestMapping("/valid")
    @ResponseBody
    public Result<LoginVO> validate(@Valid LoginVO loginVO){
        System.out.println(loginVO);
        return Result.success(loginVO);
    }



}
